package coder

import (
	"encoding/gob"
	"io"
)

type GobCoder struct {
}

var gobCoder *GobCoder = &GobCoder{}

func GetGobCoder() *GobCoder {
	return gobCoder
}

func (c *GobCoder) Encode(w io.Writer, i interface{}) error {
	encoder := gob.NewEncoder(w)
	err := encoder.Encode(i)
	return err
}

func (c *GobCoder) Decode(r io.Reader, i interface{}) error {
	decoder := gob.NewDecoder(r)
	err := decoder.Decode(i)
	return err
}

func (c *GobCoder) Register(i any) {
	gob.Register(i)
}
